package com.dylan.magic.redis.config.redis;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.*;

import javax.annotation.Resource;

/**
 * @author : ankang
 * @date : 2019/12/14 00:40
 * @Description :
 */
@Configuration
@EnableConfigurationProperties(value = MagicRedisProperties.class)
public class RedisConfig {

    @Resource(name = "stringRedisTemplate")
    private RedisTemplate<String, String> stringRedisTemplate;
    @Resource
    MagicRedisProperties magicRedisProperties;

    @Bean(name = "valueOperations")
    public MagicValueOperations valueOperations() {
        return new MagicValueOperations(stringRedisTemplate.opsForValue(), magicRedisProperties);
    }

    @Bean(name = "listOperations")
    public ListOperations<String, String> listOperations() {
        return stringRedisTemplate.opsForList();
    }

    @Bean(name = "setOperations")
    public SetOperations<String, String> setOperations() {
        return stringRedisTemplate.opsForSet();
    }

    @Bean(name = "zSetOperations")
    public ZSetOperations<String, String> zSetOperations() {
        return stringRedisTemplate.opsForZSet();
    }

    @Bean(name = "hashOperations")
    public HashOperations<String, String, String> hashOperations() {
        return stringRedisTemplate.opsForHash();
    }

}
